package muse.widgets;

import java.awt.*;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class CyclerWidget extends Widget {

    JPanel widgetBody;
    JPanel leftArrow;
    JPanel rightArrow;
    
    JLabel cyclerTitleLabel;
    JLabel selectedObjectLabel;
    
    @Override
    public Dimension getPreferredSize() {
            return new Dimension();
    }

    @Override
    public String getIcon() {
            return "";
    }

    public CyclerWidget()
    {
        this.setLayout(new BorderLayout());
        JPanel all = new JPanel();
        
        
        all.setLayout(new GridBagLayout());
        
        GridBagConstraints c = new GridBagConstraints(); 
        
        leftArrow = new JPanel () {
            public void paintComponent(Graphics g)
            {            
                int x1 = 10;
                int y1 = 2;
                
                int x2 = 22;
                int y2 = 2;
                
                int x3 = 16;
                int y3 = 16;
                
                int x4 = 22;
                int y4 = 30;
                
                int x5 = 10;
                int y5 = 30;
                
                int x6 = 2;
                int y6 = 16;
                int x[] = {x1, x2, x3, x4, x5, x6};
                int y[] = {y1, y2, y3, y4, y5, y6};
                
                g.setColor(Color.green);
                g.fillPolygon(new Polygon(x, y, 6));
                g.setColor(Color.black);
                g.drawPolygon(new Polygon(x, y, 6));
            }
        };
        leftArrow.setBackground(Color.ORANGE);
        c.fill = GridBagConstraints.BOTH;
        c.gridx = 0;
        c.gridy = 1;
        c.ipadx = 0;
        c.ipady = 0;
        c.weightx = 0.2;
        c.weighty = 0.66;
        c.insets = new Insets(0, 0, 0, 0);        
        all.add(leftArrow, c);
        
        selectedObjectLabel = new JLabel();
        widgetBody = new JPanel(){
            public void paintComponent(Graphics g)
            {
                String s = "Selected Item";
                int sLen = (int)g.getFontMetrics().getStringBounds(s, g).getWidth();
                int start = this.getWidth()/2 - sLen/2;
                g.drawString(s, start, 20);
            }
        };
        //widgetBody.setBorder(BorderFactory.createLineBorder(Color.black));
        c.fill = GridBagConstraints.BOTH;
        c.gridx = 1;
        c.gridy = 1;
        c.ipadx = 0;
        c.ipady = 0;
        c.weightx = 1;
        c.weighty = 0.66;
        c.insets = new Insets(0, 0, 0, 0);
        all.add(widgetBody, c);
        //widgetBody.setLayout(new FlowLayout());
        //widgetBody.add(selectedObjectLabel);
        
        rightArrow = new JPanel () {
            public void paintComponent(Graphics g)
            {
                /*int x1 = 0;
                int x2 = getWidth();
                int x3 = 0;
                int y1 = 0;
                int y2 = getHeight()/2;
                int y3 = getHeight();*/
                
                int x1 = 2;
                int y1 = 2;
                
                int x2 = 14;
                int y2 = 2;
                
                int x3 = 22;
                int y3 = 16;
                
                int x4 = 14;
                int y4 = 30;
                
                int x5 = 2;
                int y5 = 30;
                
                int x6 = 8;
                int y6 = 16;
                int x[] = {x1, x2, x3, x4, x5, x6};
                int y[] = {y1, y2, y3, y4, y5, y6};
                
                g.setColor(Color.red);
                g.fillPolygon(new Polygon(x, y, 6));
                g.setColor(Color.black);
                g.drawPolygon(new Polygon(x, y, 6));
            }
        };
        
        //rightArrow.setBackground(Color.ORANGE);
        c.fill = GridBagConstraints.BOTH;
        c.gridx = 2;
        c.gridy = 1;
        c.ipadx = 0;
        c.ipady = 0;
        c.weightx = 0.2;
        c.weighty = 0.66;
        c.insets = new Insets(0, 0, 0, 0);
        all.add(rightArrow, c);
        
        
        cyclerTitleLabel = new JLabel();
        JPanel widgetLabelPanel = new JPanel(){
            public void paintComponent(Graphics g)
            {
                //set the cyler title label
                //cyclerTitleLabel.setText("Cycler Widget Title");
                String s = "Cycler Widget Title";
                int sLen = (int)g.getFontMetrics().getStringBounds(s, g).getWidth();
                int start = this.getWidth()/2 - sLen/2;
                g.drawString(s, start, 10);
            }
                    
        };
        //widgetLabelPanel.setLayout(new FlowLayout());
        //widgetLabelPanel.add(cyclerTitleLabel);
        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.gridx = 0;
        c.gridy = 0;
        c.gridwidth = 3;
        c.ipadx = 0;
        c.ipady = 0;
        c.weightx = 1.0;
        c.weighty = 0.34;
        c.insets = new Insets(0, 0, 0, 0);
        all.add(widgetLabelPanel, c);
        
        this.add(all);
        
    }
    
}
